package _99练习;

import java.util.Objects;

public class Poker {

	String card;

	@Override
	public String toString() {
		return card;
	}

	@Override
	public int hashCode() {
		return Objects.hash(card);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Poker other = (Poker) obj;
		return Objects.equals(card, other.card);
	}

	public static Poker getCard() {
		Poker p = new Poker();

		// 花色
		String[] flower = { "♠", "♥", "♦", "♣", "♤", "♡", "♢", "♧" };
		int randomFlower = (int) (Math.random() * (7 - 0 + 1) + 0);

		// 数字
		int randomNum = (int) (Math.random() * (15 - 1 + 1) + 1);

		if (randomNum == 15) {
			p.card = "大王";
			return p;

		} else if (randomNum == 14) {
			p.card = "小王";
			return p;

		} else {
			p.card = (flower[randomFlower] + randomNum);
			return p;
		}

	}

}
